package ch.nortgram.countdown_worldcup_2014;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.util.Log;
import ch.nortgram.countdown_worldcup_2014.fragment.CountdownFragment;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.app.SlidingFragmentActivity;

public class BaseActivity extends SlidingFragmentActivity
	{

	private int mTitleRes;
	protected Fragment mFrag;

	public BaseActivity(int titleRes)
		{
		mTitleRes = titleRes;
		}

	@Override
	public void onCreate(Bundle savedInstanceState)
		{
		super.onCreate(savedInstanceState);

		setTitle(mTitleRes);

		// set the Behind View
		setBehindContentView(R.layout.menu_list);
		if (savedInstanceState == null)
			{
			FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
			mFrag = new CountdownFragment();
			t.replace(R.id.menu_frame, mFrag);
			t.commit();
			}
		else
			{
			mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
			}

		// customize the SlidingMenu
		SlidingMenu sm = getSlidingMenu();
		sm.setShadowWidthRes(R.dimen.shadow_width);
		sm.setShadowDrawable(R.drawable.shadow);
		sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		sm.setFadeDegree(0.35f);
		sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
		{
		switch (item.getItemId())
			{
			case android.R.id.home:
				toggle();
			return true;
			case R.id.github:
				Log.e("","pressed");
				//Util.goToGitHub(this);
				// icon oben rechts
			return true;
			}
		return super.onOptionsItemSelected(item);
		}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
		{
		//getSupportMenuInflater().inflate(R.menu.main, menu);
		return true;
		}
	}